package com.tnxst.phexamination.utils;

import android.os.Environment;

import com.tnxst.phexamination.constant.HISConfig;

import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;

public class StringUtils {

    public static boolean isNotNull(Object str){
        if (str == null || "".equals(str))
            return false;
        return true;
    }
    public static boolean isNull(Object str){
        if (str == null || "".equals(str))
            return true;
        return false;
    }
    public static String getSDPath(){
        File sdDir = null;
        boolean sdCardExist = Environment.getExternalStorageState()
                .equals(Environment.MEDIA_MOUNTED);//判断sd卡是否存在
        if(sdCardExist)
        {
            sdDir = Environment.getExternalStorageDirectory();//获取跟目录
        }
        return sdDir.toString();
    }

    public static String replace(String json){
        json = json.replaceAll("\"\\[", "[")
                .replaceAll("]\"", "]")
                .replaceAll("\"\\{", "{")
                .replaceAll("\\}\"", "}")
                .replaceAll("\\\\+\"", "\"")
                .replaceAll("\\\\\\{","{")
                .replaceAll("\n","");
        return json;
    }

    public static Map<String,Object> getDataMap(){
        Map<String,Object> data = new LinkedHashMap<>();
        data.put("ProductCode",HISConfig.PRODUCT_CODE);
        return data;
    }

    public static Map<String,Object> getPageDataMap(Integer pageSize, Integer pageIndex){
        Map<String, Object> dataMap = getDataMap();
        dataMap.put("PageSize",pageSize);
        dataMap.put("PageIndex",pageIndex);
        return dataMap;
    }
}
